package com.config;

import com.config.dao.UserDao;
import com.config.dao.impl.UserDaoImpl;
import com.config.service.UserService;
import com.config.service.impl.UserServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//配置类注解==  xml文件
@Configuration
public class AppConfig {

    // @Bean：将方法的返回值交给spring 管理，对象名默认为方法名
    // 如果设置对象名，在 @Bean注解中通过name属性单独设置
    @Bean(name = "userDao1")
    public UserDao userDao(){
        return new UserDaoImpl();
    }
    @Bean
    public UserService userService(UserDao userDao){
        UserServiceImpl service = new UserServiceImpl();
        service.setUserDao(userDao());
        return service;
    }
}
